package core;

import java.util.ArrayList;

public class Constraint {
	private String type;
	private String constraintName;
	private ArrayList<ConstraintReference> references;
	
	public Constraint(String constraintName, String type) {
		this.type = type;
		this.constraintName = constraintName;
		references = new ArrayList<ConstraintReference>();
	}

	public String getType() {
		return type;
	}
	
	public String getConstraintName() {
		return constraintName;
	}
	
	public void addContraintReference(ConstraintReference reference){
		references.add(reference);
	}
	
	public ArrayList<ConstraintReference> getContraintReference() {
		return references;
	}

	public boolean hasColumn(Column col) {
		for(ConstraintReference ref : references){
			if(col == ref.getColumn()) {
				return true;
			}
		}
		return false;
	}

	public boolean isReferenced(Table table) {
		if(references.size() == 0){
			return false;
		}
		
		
		if(references.get(0).getRefColumn() == null) {
			return false;
		}
		
		return references.get(0).getRefColumn().getTable() == table;
	}
}
